﻿using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;

public class MouseUp : MonoBehaviour, IPointerUpHandler
{
    private UnityEvent onMouseUp = new UnityEvent();
    private UnityEvent<PointerEventData> onMouseUpWithData = new UnityEvent<PointerEventData>();

    private UnityEvent onLeftMouseUp = new UnityEvent();
    private UnityEvent<PointerEventData> onLeftMouseUpWithData = new UnityEvent<PointerEventData>();

    private UnityEvent onRightMouseUp = new UnityEvent();
    private UnityEvent<PointerEventData> onRightMouseUpWithData = new UnityEvent<PointerEventData>();

    public void AddUp(UnityAction action)
    {
        onMouseUp.AddListener(action);
    }

    public void AddUp(UnityAction<PointerEventData> action)
    {
        onMouseUpWithData.AddListener(action);
    }

    public void AddLeftUp(UnityAction action)
    {
        onLeftMouseUp.AddListener(action);
    }

    public void AddLeftUp(UnityAction<PointerEventData> action)
    {
        onLeftMouseUpWithData.AddListener(action);
    }

    public void AddRightUp(UnityAction action)
    {
        onRightMouseUp.AddListener(action);
    }

    public void AddRightUp(UnityAction<PointerEventData> action)
    {
        onRightMouseUpWithData.AddListener(action);
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        onMouseUp.Invoke();
        onMouseUpWithData.Invoke(eventData);

        if (eventData.button == PointerEventData.InputButton.Left)
        {
            onLeftMouseUp.Invoke();
            onLeftMouseUpWithData.Invoke(eventData);
        }
        else if (eventData.button == PointerEventData.InputButton.Right)
        {
            onRightMouseUp.Invoke();
            onRightMouseUpWithData.Invoke(eventData);
        }
    }
}